package com.framework.validated.common;

import com.framework.validated.exception.ExceptionEnum;
import lombok.Getter;

@Getter
public class R<T> {


    private Integer code;
    private String msg;
    private T data;

    public static <T> R<T> success(){
        R<T> tr = new R<>();
        tr.code = 200;
        tr.msg = "success";
        return tr;
    }

    public static <T> R<T> success(T data){
        R<T> tr = new R<>();
        tr.code = 200;
        tr.msg = "success";
        tr.data = data;
        return tr;
    }

    public static <T> R<T> error(){
        R<T> tr = new R<>();
        tr.code = 500;
        tr.msg = "error";
        return tr;
    }

    public static <T> R<T> error(T data){
        R<T> tr = new R<>();
        tr.code = 500;
        tr.msg = "error";
        tr.data = data;
        return tr;
    }

    public static <T> R<T> error(String msg, T data){
        R<T> tr = new R<>();
        tr.code = 500;
        tr.msg = msg;
        tr.data = data;
        return tr;
    }

    public static <T> R<T> error(ExceptionEnum exceptionEnum, T data){
        R<T> tr = new R<>();
        tr.code = exceptionEnum.getCode();
        tr.msg = exceptionEnum.getMsg();
        tr.data = data;
        return tr;
    }

}
